package com.lineage.server.serverpackets;

import com.lineage.server.model.L1Character;

public class S_MoveCharPacket extends ServerBasePacket {
  private byte[] _byte;
  
	private static final byte HEADING_TABLE_XR[] = { 0, -1, -1, -1, 0, 1, 1, 1 };
	private static final byte HEADING_TABLE_YR[] = { 1, 1, 0, -1, -1, -1, 0, 1 };
  
  public S_MoveCharPacket(L1Character cha) {
    this._byte = null;
    int locx = cha.getX();
    int locy = cha.getY();
    int heading = cha.getHeading();
    locx += HEADING_TABLE_XR[heading];
    locy += HEADING_TABLE_YR[heading];
    writeC(10);
    writeD(cha.getId());
    writeH(locx);
    writeH(locy);
    writeC(cha.getHeading());
    writeC(129);
    writeD(0);
  }
  
  public S_MoveCharPacket(L1Character cha, int locx, int locy) {
    this._byte = null;
    int heading = cha.getHeading();
    locx += HEADING_TABLE_XR[heading];
    locy += HEADING_TABLE_YR[heading];
    writeC(10);
    writeD(cha.getId());
    writeH(locx);
    writeH(locy);
    writeC(cha.getHeading());
    writeC(129);
    writeD(0);
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
